import PyTaskbar
from enum import Enum
# import PyTaskbar
# taskbar_progress = PyTaskbar.Progress(int(app.wm_frame(), 16))  # Instantiate a new progress object
# taskbar_progress.init()  # Initialize the progress bar
# taskbar_progress.setState(
# "loading")  # Set the progress bar state to normal (Available: loading, normal, warning, error)
# # taskbar_progress.setProgress(50)  # Set the progress bar value to 50%

class TaskProgressState(Enum):
    STATE_NORMAL = 'normal'
    STATE_LOADING = 'loading'
    STATE_WARING = 'warning'
    STATE_ERROR = 'error'
    STATE_DONE = 'done'

_task_progress:PyTaskbar.Progress | None = None

def init_task_progress(app):
    global _task_progress
    _task_progress = PyTaskbar.Progress(int(app.wm_frame(), 16))
    _task_progress.init()
    _task_progress.max = 100

def set_task_progress_max(max_progress):
    _task_progress.max = max_progress

def set_task_progress_state(state: TaskProgressState):
    _task_progress.setState(state.value)

def set_task_progress_progress(cur_progress: int):
    cur_progress = int(cur_progress / _task_progress.max * 100)
    _task_progress.setProgress(cur_progress)